//
// main.cpp for  in /home/jousse_f//afs/rendu/math/205inter
// 
// Made by florian jousseau
// Login   <jousse_f@epitech.net>
// 
// Started on  Wed Apr 25 12:43:23 2012 florian jousseau
// Last update Thu Apr 26 13:09:41 2012 florian jousseau
//

#include	<iostream>
#include	<stdio.h>
#include	<unistd.h>
#include	<stdlib.h>
#include	<math.h>

double		fct(double x)
{
  return (exp( -(x*x) / 2));
}

double		simpson(int n, double a, double b)
{
  double	X;
  double	h;
  double	part0 = fct(a) + fct(b);
  double	part1 = 0;
  double        part2 = 0;
  int		i = 0;

  h = (b - a) / n;
  while (i <= (n - 1))
    {
      X = a + (i * h);
      if ((i % 2) == 0)
	part2 += fct(X);
      else
	part1 += fct(X);
      i++;
    }
  return ((b - a) / (n * 6.0)) * (part0 + 2.0 * part2 + 4.0 * part1) * 2.0;
}

int		main(int ac, char **ar)
{
  double	res = 0;
  double	fa = 0;
  double	fb = 0;
  int		n = 2000;

  if (ac < 3)
    {
      std::cerr << "Usage : ./205inter a b" << std::endl;
      return (-1);
    }

  fa = (1 / (sqrt(2 * M_PI))) * simpson(n, -1000, atof(ar[1]));
  fb = (1 / (sqrt(2 * M_PI))) * simpson(n, -1000, atof(ar[2]));
  res = fb - fa;

  std::cout.precision(3);
  std::cout << "P(" << atof(ar[1]) << " <= Z <= " << atof(ar[2]) << ")" << " = "<< res << std::endl;
  return (0);
}
